﻿Imports System.IO

Public Class Form1
    ReadOnly key As Byte = 235
    Dim Pfad As String
    Dim zaehler1 As Integer = 0
    Dim zaehler2 As Integer = 0
    Dim zaehler3 As Integer = 0
    Dim Daten As Byte()
    Dim Bits(1, 2) As UShort
    Dim Kbits(7) As UShort
    Dim ByteVal() As Byte = {1, 2, 4, 8, 16, 32, 64, 128}
    Dim buff As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Daten = My.Computer.FileSystem.ReadAllBytes("c:\test\test.txt")
        MsgBox(ConvertByteArrayToString(Daten))
        bytetobit()
        keytobit()


        'Dim Testdaten As Byte = 77
        ''MsgBox(Testdaten)
        ''MsgBox(key)
        'Dim testtt() As Byte = Nothing
        'testtt(0) = 15
        'testtt(1) = 26
        'Dim x As String

        'Dim kontrollwert As Byte = 166

        ''MsgBox(kontrollwert)
        'If BXOR(Testdaten, key) = kontrollwert Then
        '    MsgBox("Richtig")
        'Else
        '    '   MsgBox("Falsch")
        '    MsgBox(BXOR(Testdaten, key))
        'End If
        ''OpenFileDialog1.ShowDialog()
        ''Pfad = OpenFileDialog1.ToString.Remove(0, 56)
        ''datreader2 = New StreamReader(Pfad)
        ''While (datreader2.Peek() <> -1)
        ''    If zaehler1 > 7 Then
        ''        zaehler1 = 0
        ''        zaehler2 = zaehler2 + 1
        ''    End If
        ''    int(zaehler1, zaehler2) = (datreader2.Read) - 48
        ''    zaehler1 = zaehler1 + 1
        ''End While
        ''ReDim Preserve int(7, zaehler2)
        ''ReDim buf(8, zaehler2)
    End Sub

    Public Sub bytetobit()
        ReDim Bits(Daten.Length - 1, 7)
        For i As Integer = 0 To Daten.Length - 1
            For b As Integer = ByteVal.Length - 1 To 0 Step -1
                If Daten(i) And ByteVal(b) Then
                    Bits(i, zaehler1) = 1
                Else
                    Bits(i, zaehler1) = 0
                End If
                zaehler1 += 1
            Next
            zaehler1 = 0
        Next
    End Sub

    Public Sub keytobit()

        For b As Integer = ByteVal.Length - 1 To 0 Step -1
            If key And ByteVal(b) Then
                Kbits(zaehler1) = 1
            Else
                Kbits(zaehler1) = 0
            End If
            zaehler1 += 1

        Next
        zaehler1 = 0
    End Sub

    Private Function ConvertByteArrayToString(ByVal dats() As Byte) as string
        Dim text12 As String = Nothing

        text12 = BitConverter.ToString(dats)
        Return text12


    End Function


    Public Function BXOR(ByVal Data As Byte, ByVal key As Byte) As Byte
        Dim test As Byte
        test = Data Xor key
        Return test
    End Function


End Class
